/*
********************************************************************************
* Copyright (C) 2021, xiang.D <dx_65535@163.com>.
* All right reserved.
*
* File Name   : factory_method.cc
* Author      :
* Version     : V1.0
* Description :
* Journal     : 2021-10-10 init v1.0
* Brief       : Blog: https://blog.csdn.net/qq_38750572?spm=1001.2014.3001.5343
* Others      :
********************************************************************************
*/
#include <iostream>

using namespace std;

/* Phone abstract interface */
class CPhone
{
public:

    virtual ~CPhone() {}

    /* Function interface for phone */
    virtual void showLabel() = 0;
    virtual void call() = 0;
    virtual void takePicture() = 0;
    virtual void messages() = 0;
};

class CHwMate : public CPhone
{
public:

    void showLabel()
    {
        cout << "Welcome Mate Serial!" << endl;
    }

    void call() {}
    void takePicture() {}
    void messages() {}
};

class CHwNova : public CPhone
{
public:

    void showLabel()
    {
        cout << "Welcome Nova Serial!" << endl;
    }

    void call() {}
    void takePicture() {}
    void messages() {}
};

class CHwP : public CPhone
{
public:

    void showLabel()
    {
        cout << "Welcome P Serial!" << endl;
    }

    void call() {}
    void takePicture() {}
    void messages() {}
};
/* End Phone implementation */

/* Factory abstract interface */
class CHuaWeiBusiness
{
public:

    virtual ~CHuaWeiBusiness() {}

    /* Production interface for phone production */
    virtual CPhone *getPhoneInstance() = 0;
};

class CHwMateProducer : public CHuaWeiBusiness
{
public:

    CHwMate *getPhoneInstance()
    {
        return new CHwMate();
    }
};

class CHwNovaProducer : public CHuaWeiBusiness
{
public:

    CHwNova *getPhoneInstance()
    {
        return new CHwNova();
    }
};

class CHwPProducer : public CHuaWeiBusiness
{
public:

    CHwP *getPhoneInstance()
    {
        return new CHwP();
    }
};
/* End Factory implementation */

int main (int argc, char *argv[])
{
    CHwMateProducer theHwMateProducer;
    CPhone *theMatePhone = theHwMateProducer.getPhoneInstance();
    if (NULL != theMatePhone) {
        theMatePhone->showLabel();
        delete theMatePhone;
        //delete theHwMateProducer;
    } else {
        cout << "theMatePhone is NULL!" << endl;
    }

    CHwNovaProducer theHwNovaProducer;
    CPhone *theNovaPhone = theHwNovaProducer.getPhoneInstance();
    if (NULL != theNovaPhone) {
        theNovaPhone->showLabel();
        delete theNovaPhone;
    } else {
        cout << "theNovaPhone is NULL!" << endl;
    }

    CHwPProducer theHwPProducer;
    CPhone *thePPhone = theHwPProducer.getPhoneInstance();
    if (NULL != thePPhone) {
        thePPhone->showLabel();
        delete thePPhone;
    } else {
        cout << "thePPhone is NULL!" << endl;
    }

    return 0;
}


